package com.ok.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
@ConditionalOnClass({MybatisPlusInterceptor.class, BaseMapper.class})
public class MyMeta implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
//        log.info("公共字段填充:{}",metaObject.toString());
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime",LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
//        log.info("公共字段填充:{}",metaObject.toString());
        metaObject.setValue("updateTime",LocalDateTime.now());

    }
}
